package io.zhengsh.nio;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

public class FileChannelWrite2 {

	public static void main(String[] args) throws IOException {
		// 创建 FileChannel
		RandomAccessFile fromFile = new RandomAccessFile("C:\\a.txt", "rw");
		FileChannel formChannel = fromFile.getChannel();

		// 创建 FileChannel
		RandomAccessFile toFile = new RandomAccessFile("C:\\c.txt", "rw");
		FileChannel toChannel = toFile.getChannel();

		long position = 0;
		long count = formChannel.size();
		formChannel.transferTo(position, count, toChannel);

		formChannel.close();
		toChannel.close();
		System.out.println("end");
	}
}
